refactoring api controller and models