Fix for intermediate variables being expanded multiple times