added error handling and modified record type