reorganized + cleaned code, retry connections for client