Moved the algorithm inside a class