Some error checking is added.