rewrote reprint algorithm