fixed broken figure calculation function