Remove uses of deprecated table.foreach