modified error trapping logic