Add unit tests

* Fix math functions to accomodate for empty lists
* Unit tests need serious refactoring....