fix active_branch & misc.

Not sure how you'll feel about the first and last of these three commits; the second (199e697) seems pretty important.