improved server connection/authentication code