Refactored api and service layer