second refactoring pg 22
adding encoding map, 3rd refactoring pg 27