Some changes to fix random restarts