extended to handle two branches