Improved return by reference handling