Added Query and Exception logging