Increasing performance by reducing db calls and refactoring logic for Gateway objects