Improved generator, fixed branch counting.