factor out encoding, for readability