Make check_variables more robust