extract common packages handling code