fix integer arithmetics overflow (Issue #19).