fixed double counting, write new files