check query exists before accessing properties