Distributions, First Integrals and Legendrian Foliations