Corrected extend function