Fixed bug whereby queries sometime return nil