unlinking and closing tempfile of batchgroupings

and fixed some tests