Added better error checking.