fix arithmetic overflow