removed unused math and changed "if" around