Simplified algo, removed token classes