improve output function with ref (not pointer)