Added threading functionality to Algorithm and added tests.