refactored into files, checking alogithm, co_rank seems buggy.