Some error checking added.