Change the structure of resolve_gates to make it more inuitive

Work in progress