change table.foreach to for in pairs