Fix extend function