refactor with a service layer