Refactored code, prepared to finance api call'