added automatic save and resume