fix bug, related with recursive function and the logic