[#1826] Update algorithm to handle more cases
[#1826] Update algorithm to handle more cases

Also add more output information and speed things up a bit

akvo/akvo-rsr,akvo/akvo-rsr,akvo/akvo-rsr,akvo/akvo-rsr