replaced string concatenation with stringbuilder
fixed compareTo