logic and style fixes