Reduce variable use/duplicate code.
Added/removed newlines to make the code more readable.
Merge pull request #1593 from kimegede/more-readable-code

More readable code