Improved the recurive funtion and separated it into an independent JS file