Some error checking code added.