[main_ai] Fixes several bugs, restore full trajectory