small refactoring in gateway