Fixed rare conditions bugs in context listener.