Updated error checking code x2