This logic is duplicated from line 73