More refactoring and cleanup
missing closing paren