Implemented spigot algorithm.