changed filehandling to with