WIP: Clean the code in two blocks, compiles
WIP: A compilable version of the code, but probably not working yet.
WIP:  Partial completion of KNN integration with EM.
WIP: DO NOT COMMIT THIS PATCH

This is to make a fast test.  DO NOT commit this without reverting the test.