refactor the math functions
improved dense math functions