update extend function to have better semantics