Added main file functionality only for autosave mode, the code should be checked and revised if neccessary