rank implementation