added Shuheng Dai's code from Dropbox