Some additional tests and refactoring