refactored to recurrsively generate folder structure