Move guard function out of session.py