I see you assign `hasAnd` at the end of this block. The below codes blocks seems very similar, please rethink to reuse code instead of copying code.