Updated read_command_stream function. Other minor changes.