fix encoding and add more tests