Fix KeyError : access token & Refactored code