more elegant iteration solution