Refactored the __extends function