implemented suggestied to fix integer overflow