Completed connection hand-shake handling, tho I am not certain
about the response returned from the server on invalid authorization key
Added close handling to prevent connection leaks