fixed bug, now output is correct