Fully implemented the gate