refactor for opening files in single instance