added file replace logic