performance and coding style fixes