Bugfix: prevent overflow by replacing int with double