Refactored AbstractWait. Fixes #527.