Add a couple of tests and refactoring