Minor refactoring and code cleaning.