Re-wrote arithmetic functions to prevent memory leaks, added static versions of all functions.