added error handling to connection