Optimize output size of kpm pack

parent #652 
Can we keep a dictionary instead?