Optimazed fix and restore mem