fix issue where token may be undefined