added a bunch of stuff for encoding entities. Currently broken