Refactoring in rest controller