- restructured code
- improved timeout handling