An Algorithm for Horizontal Decompositions