changed indexing logic by using primary keys instead