fixed bugs with doing calculations more that once