Minor fixes and several performance improvements