Implementation for algorithms on http://decomplexify.blogspot.com/