added and tested error checking