Cleaned up restore code