Changes after testing Fei's code