Refactor math helper