Fix a bug where indexes were not being updated properly. Add a test so it does not happen again. Change boolean indexes to a sorted set implementation (for easier updates)