refactored the save page source code