Refactored API Access Code