Write state into the right place