better algo for pi