Refactor packaging subprocess code