word count scala
extract count function to make it read better