cosmetic changes and lots of logging in algorithm