Improve coding style and logging