Fixed some issues preventing the algorithm from running properly.