Minor refactoring changes and improvements