Fixed utils.get_variables to deal more robustly with context contents that don't support .keys().