Implemented a probably very poorly written restoration function