Improve code style

Use a StringBuilder instead of String concatenation
Avoid too nested structures

Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>