Cleaned up connect and close error handling