tested and fixed the new output function