Fixing bug with incorrect exponent sent to gen_session_key
Fixing issue with closing socket early