first iteration of the KDE algorithm