Added safeguards for empty train list