fix unread count bug and refactor.