Minor refactoring and comment additions