many general tweaks, plus knn with cursors almost finished