Working on generalizing lcsm.  Basic algorithm made.