Implementing proper cursor behavior