wordCount with state machine pattern