Improved file replacement