Restored and tweaked the old logic for pasting