fix some overflow issues