Refactor waitForCallback to waitFor