refactor for Apiscontroller