change code to be more fault-tolerant