Logging and various fixes