Fix bugs caused by exception