added some error checking and we are good to go