DB query bug fixed