did a bunch of error checking