Updated encode.c with optimized attribute value