Switch branches instead of applying/reverting to master.

Also added a close inventories patch.