refactor traffic manager and add more tests