Implemented client->proxy timeout.
Cleaned up the code