Removed unused code/imports. Added writeMessage method.