Improved logging. Refactors.