Extended and refactored the logging