Numerous bug fixes and minor enhancements