Minor refactoring in shell.py