Working version of scale invariance algorithm