move comp/decomp into common function