Refactor capability packing/unpacking