added checking for trajectory validity