Updated gate openning  logic