added code to calculate character frequency