added some basic error checking