Fix wait loop