Fixed the extend function so that it handles null values as null rather than converting them to an object