Added option to set custom timeout for wait functions
- plus small reorganization (function order changed, formatting unified)