minor performance improvements and minor bug fixes