Replaced wasteful wait loop with wait / notify.