Moved checkVars to a function too