added some rudimentary error checking