Moving json and xml encoding to helpers (ty Mr. Ceeram)