fix rank counting