First version
Tests, refactoring and bugfixes