refactor and cleanup

Eliminate unnecessary cached file read and double execution of
the 'session' method.

Also separate out 'refresh_session!' method for next patch.
add retry functionality and small error handling

Note that access token can be expired earlier than the reported
expiry time (off by about half an hour), which will cause '401
Unauthorized' error. Retry can hadle this situation.