Counting brackets properly