version 3: removed isInner and branch -> slower