Context change

This consists of the first two commits from #1269, rebased and slightly modified.
The indentation needs to be fixed on l. 110