optimize closure function codec