refactored APIcontroller