Optimizations + new metric indexes

We refactor and rewrite several metric indexes and sequence indexes to
achieve better times.
completing the previous commit