updated handleMessage method: added mode argument:
update comments in the handleResponse method