Optimisations and cleanup.
Using StringBuilder and Buffer, fixed options reset on crash.