Bug fixes and code enhancements