Added logging back and code to test that the knot detector works. More refactoring.