refactoring service and text writing