changed file copy, read and write methods to reuse the existing code