Improve log messages and fix bugs