Fixed a bug in pruning pass which caused terms to always be pruned in LIFO order instead of the correct order.