fix + refactoring

fixed mixing of sets in repeated open of already running program. And
some refactoring.