Implements more of do_bgfg, passing test 10