Added check for variables fixes #3236

Does this look okay?