Problem 3 + refactoring

Moved math functions to common-math.