Just a few changes:

Did some renaming, removed while(true) 
and changed StringBuffer to Builder since we dont need threadsafeness