Improvements to shell thread, general cleanup