repair a bug in function moveToIndex