various fixes
refactor and add functionality to gate API, for #2107