Extending Stable and Popular Matching Algorithms from Bipartite to Arbitrary Instances