Replace with more usable encode algorithm.