Adding query/response and some bugfixes