use StringBuilder instead of StringBuffer, some toString format fixes for functions