added minor error checking