working on gen algo