refactor api controllers and models