some code formatting and added math functions