various bug fixes and performance enhancements