refactor and add save feature