refactored backup, more generic backup function