Merged Wout's and Jasper's versions