Refactor states a bit