flush the manager outside the for loop
removed unsued variable
removed unused use statement
added missing file line end