Fixed a major bug where state files were not generated corectly