More tests & refactoring