example 8-4: refactor of message counter