More refactoring, implement oauth2 refresh token support