Moved clipboard restoration to a cleanup phase after completion of the handlers to ensure that delays in the UI do not cause the clipboard to be reset before the past command goes through.