Refactored some math functions to better represent their meaning.