refactored package creation into shared function.