Added null check when retreiving query results