Move state setting to a more sensible place