added better connection refused error handling, updated logout function