function only fires if in right state