Cleaning up and enhanced logging