refactor file opening code
minor refactoring
add 'only one instance' functionality