Implementing the cursor code