changed abit in recursive function so it should work properly