CursorState code tidy-up