redesign of branch generation algo, huge speedup