Final combined algorithm as of 2013-12-14