more tests fix one issue in encode
More test and fix function to pass the test