Added error handling for null values