rank retrieval cleanup and optimization