fixed bugs caused by interger overflow