as you pointed out in my pull request you should create a copy of encoding before modifying it.