handle errors and restarting better