Moved get_unread_count to a function