refactored to use common code