implemented compact coding algorithm