math: refactoring, solved one exception which might be related to #11.