rewrote message queries and fixed pagination