fixed bug IPF which incorrectly produced diagonal values, additional
refactoring and unit-tests.