Code cleanup

Code cleanup: Added comments, removed unnecessary code, fixed spacing and alignment
Bug fix: Fixed crash when making an API request without internet connection