added packing functions, moved parsing mechanism to outer function