Some formatting, NPE checking and log messages.