various python code optimizations; shuffle I/O to shell classes