refactoring of gate keeper to reduce db read