Bug fixes for response encoding