Improve torus performance, refactoring