Correctly create dir if it doesn't exist
Added vars to front of main functions