Move encoder function to own module.