Code tidied, and using StringBuilder for efficiency where possible.