Bugfix + code refactoring + first tests