Cleaning up and adding math code