bug fixes and various enhancements