Cleanups and refactorings

This contains cleanups and refactorings on the k-NN recommenders. Not yet ready for merging.