Minor refactoring and cleanin