Changes to receive thread.

This commit makes the following changes:
* optimises the receive thread.
* adds an array to prevent storing duplicate responses
* match header from responses.