fixing bug for algo recusrion