add an optimization step to remove duplicate assignments