Separated cursor encoding into separate function, and made it more explicit