Refactor and fix backup/restore
Created by: dzaporozhets