Modify some bugs to make program robust