refactored a bit + added restore option