Logging and bug fix