added tests for math libs
pushed various optimizations recommended by @3b