Fix bug with library mode, and add constraint for checking trapezoid format.