moved structure from master, fixed bug with encoding