add in a bit more error checking