Fixed bug when copying to files to wrong directory