changes to error handling and returned data format for better error handling