added math functions, bug fixes