refined logic on rank computation