Bug fixes and enhanced logging