Backported some things from lab.netzgestaltung.net.