Refactored Api.cs