indices should be inserted at the end