many bug fixes and enhancements