more generic findRoot

move code