Added a timeout thread to auto close the connection
Changed timeout code to use closed state and updated submodule with exposing close state
Implented code to resolve pending requests
Moved auxiliary functions out of main and into modules