Refactor and add route tests