Added main calculation function.