Tweaked Anna to use discussed algorithm