removed duplicated code by adding a method. Removed a bug that folders where not created.