Updated search next train logic