refactor duplicate code
fix error
Merge pull request #792 ClemensSahs:hotfix/refactor-duplicate-code

refactor duplicate code
Fixed few empty spaces/formatting issues