setting cursor to the proper position