move some function to service.