cleanup and refactor.