wrapped algorithm in a closure
bug fix