implement compress and expand.