math and refactor