Initial refactor of math submodule