Optimize constructing the state string