added encoder and some test cases