lots of additions, encoding almost done