fixed looping on second to last node