modified code on TrackMaster