Is it necessary to change cursorX+n-1? It will either get overwritten by the memmove or the for loop below.