solve a bug in gmd
improve a lot