Clean up shell main loop