add encode test, more edits