Fix bugs in train