Refactoring, put math classes into library instead