refactor some function into service