converted code in old/track.cpp