Added Some code to do some error checking.