Bug and style fixes