changed exception catching according to Cory's comments