added some comments and moved the secondary rank check as a parameter