Clean up and document the core math functions