fix wait implementation