Improve context handling