Adding error checking