Changed writeMessage() slightly to reduce IF statements.