This is a follow up of commit b40a006d which closees BUG 169054. It turns out the old code already has most parts of similar logic. So remove duplicated logic in the code.