Better way to avoid duplicated printing?