fixed bug that caused the leaving trains to not be sorted properly