Modified root detection to work better.