Modified step 8 to save results in k_i-s_j (Issue #3)