fix hdg overflow bug