bug trapping code