Finished most of permanent algo, just need to tweak it so that the double edges added go to both sides of each matching