added basic error checking [1341]