Add recursive bit-flags algorithm