Minor refactoring and syntax fixes.