refactor scanning for token