added timeout and wait