NPE fixes: Query runs fine now