Mostly working encoder example