completed math refactor