Moved last-time lookup inside main program loop