Performance improvements and removed unnecessary string declarations.

Used StringBuilder instead of string. Other unnecessary string declarations removed.