made the encoding callback function anonymous for clarity