minor refactorings. keep only best K results in memory