added bounds checking to pos argument
made single character frequencies optional
factored up printing of counts