Added the rootIndex cut off back into the code

Accidentally removed it when adding the 0 check