fixed some state related bugs