ok, algorithm seem to work
not optimized yet