frequency count, and some improvements on regex