refactored ContextListener