This code contained several bugs that mis-formated the output. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>