refactoring and fix routes