Fix issue with index in trainer