Debugged algorithm
More debugging