Minor refactoring and commenting