Small refactoring of obtain token