Refactor object function encode