Replace function and file structure impoved