Worked on the algorithm for variable expansion