updated encode.c -- final version