Fixing query for collecting messages ready to be queued