Added final level of encoding. Various fixes.