Refactoring and tests passing now.