Initial cleanups and refactorings