When writing state make sure to create the dir if it doesn't exist
Fix bad variable name
Merge pull request #11 from tas50/state_dir

Avoid state dir errors when it doesn't exist