With some minor optimizations. Gather op only 2 threads.
Added constraints feature.