Better cursor movement function