Simplified reference implementation of pack operation