Added some error checking.