refactor session logic with duplicate message checker