Refactoring and cleanup 3