Fix output functions
A working version