Fixed bug: id_query got into very long loop for id -1.