fix logic error in anti-overwrite code