Finally a runnable version with right output