Maybe do this outside the foreach? or does getChildren change the state?