Added tests and refactored some code
New version 1.4.0 with lots of tests and refactoring