refactor gate mode