Bug fixes and style fixes