Refactor api routes