moved encode to helper, and only test it from helper.