This code looks pretty similar to positionAtArrayElement. Maybe some refactoring is in order (after we get this change in perhaps)?