Checking code reworked to be more robust.