Bugfixes and additional math tests