BUG - Refactor the API code