Fix a bug with defer variable replacement