Started some testing and refactoring