Remove old function
Move encode preparation into separate file