some style fixes and refactoring