Refactor and removal og duplicate code.
Refactor of message logging.
Oops, for got file.