Use stack instead of list in differentiator