Fixed Code in recursive functions