Fix some state bugs