Fixed a few bugs, added State counter