Move encoding functionality and fallbacks into helpers