made the encode fix at line 861