added basic error checking