First working version of algorithm committed.