Begun refactoring and test