Lots of changes for supporting color output.