avoid use of pow() in distance calculation, speeding them up an order of magnitude (thanks quietus!)