Changed next() to next_token()
Moved test code so only runs if module is run as __main__