added final check to waitFor