optimize context handling