Changed string building to use StringBuilder

as well as other memory things