Switch to implicit loops, simplify branching