fix optmizing seq bugs
refactoring general optimization patterns; add test to prim-propagation