reoganize code and add the posibility to restore an existing magento