Recode all algorithms

Implementing ttmath, reducing  runtime