Error checking added.
Some error checking.