adds a check of if there is a tracked item
change the scope of the end var