Gate logic