added null checks for leaf and phrase matcher