Fixed bug when cursor would be out of range and further than the buffer length