Added nil check for querying views with keys