Extracted constants and improved error messages and logging