A lot of refactoring and started adding tests