ENH: Some style fixes and refactoring