improve context management