Modify some functions to alleviate overflow / precision errors