Fixed a mess of branching and merging