Small changes in waitfor function, need more changes before it will work