Cleaned up some math functions for easier maintenance.