add comments to gate, and refactor