Work on gate merge logic. This code will not (probably) compile yet.