upated encoder functions