faster. math algorithm