fixing issue with state file writing