Improved rank and lex_smaller_count