better handling of fromIndex / toIndex