Refactor parse of states to a separate function.