adding lots of error checking