optimize query and add status message for tagging