refactor math.js and fix math test