fixed bug in outer foor loop: data was overwritten every loop cycle, so the second cycle there was an runtime error