Removed all trailing whitespace and adapted refactorings.

This commit removes all trailing whitespace from the code and
also adapts the refactorings so that they don't create unnecessary
whitespace (e.g. indented empty lines to separate methods).
Insert extracted method after its previous surrounding method

Fixes #1001808