More tests & refactored a bit