fixes #791 - improved waitFor performance.