Improved logging, some code clean-ups