calculates rank