Merged improvements from Matthias Guth