New algorithm that applies an 'elastic' breadth first search in order to always find the optimal solution. Refactored some code into another file.