An algorithm for the construction of 3-manifolds from 2-complexes