General bug fixes and enhancements