Fixed compilation and calculation errors