fix a mistake in 64a419a,  further refactoring