Added some improvements from convertToSequenceIndex procedure.