Added support for waiting with timeout in case of multi-threaded execution + minor refactoring.