Fixed Database Query Bug