Added periodic cleanup of pending messages