Fix $keep variable scope (refs #2221)