Logging and some exception handling.