enhanced logging and code cleanup