fixed some bugs, implemented losy constraints collapsing