changed the program to fit and save trajectory in 4 different modes