Refactor states