Minor refactoring and extra comments