added error trapping