fixed branch logic