Found the indenting and bracketing quite confusing. Tidied it so the code is easier to read.
Merge pull request #3098 from fluffyfreak/tidyup

tidyup