Cleanups, move some math utility functions to a new module, etc.