introduced some error checking