Added docstring to function.
Added comments to clarify some code.
Fixed bug in setting number of neighbors and the corresponding test script.