move the auto save function out of doc ready to the main scope