changes to reduce the stack requirements of the encoder