Fix tests and branch logic