Move all unpadding logic to C