added bestK implementation; fixed various bugs