bug found because of double usage of $file variable