Setting up tests and refactoring