improve state flow