Added check for session existance in middleware