refactor duplicate code on route