Replacement for #3940

My changes from #3940 to the correct branch. I am sooo sorry about that. When you come to merge 4.1 into the master later on, git should resolve the whitespace errors itself.