refactored to simplify add/remove indexes