refactoring controller and endpoint