Implementing pack function