refactor to services and controllers