refactor track function