moved tls logic to an own file