bug fix in gd.cpp