Fixed extend() function