Improved error trapping