add dfn for main algo
fix referential issues