Small refactorings, compacting and cleanup