Fixed logic for training / queries. Fixed list index bug.