Added more logging and debugged minor problems when running the algo.
Merging with remote branch.