Added increased error checking