correct context handling (but maybe too complicated)