Updated error handling to use correct fields