query loop is fixed