Code cleanup and restore download functionality