Added a flag and gate and stuff