Make cursor-related functions faster and more idiomatic