improved generating of LP, better exception handling