Improve backup and restore handling
Code refactoring