Implement alg

Fixes #3