Fix hang when unexpected token encountered