Improved logging. Small improvements to code