Refactor APIService