Add additional tests and refactoring