Improved cursor handling