Fix a few bugs in validate and add var_log helper function.