small bug fixes and performance improvements