Some error checking changes