added automatic saving functionality