Changed math algorithm