HDS stdout piping fix; lots of code cleanup