added encoder &  refactoring