Threw in a little more error checking.