IMPLEMENTED TOR

complete code refactoring