implemented algorithm for KSWCF