refactor for selfcontained executables (incomplete)