Fixed some error checking.