Fixed (removed) size() - 1 in for loop. More reliable detection now.