reorganized the structures of the algorithms