refactor code of router