Implemented pack function and got it to be tailrec