refactoring of shell main() into modular function