[option] change recursion to iteration so as to improve efficiency