Bug fix and style fixes