First algorithm - first application

A quick rewriting of Danvk's code