added proper copy file function