improving error handling and default values