compression code improvement based on discussion