more unit tests, fixes for state changing logic