add logic for rank