Trying to find what is not working right in the rank_k algorithm