Have you tried debugging the code by adding println()s to show execution flow?

Why are you using the append() method?