more state work and fixed the bug