Working code with different output format